package com.jiazhong.ssm.test03RestFul.controller;

import com.jiazhong.ssm.test02响应数据.pojo.User;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther:shuXin
 */
@RestController
@RequestMapping("user")
public class RestFulController {
    /**
     * 查询分页的方法
     *
     * @param page 查询的页面
     * @param size 查询每页的条数
     * @return
     */
    @GetMapping
    public Object queryPage(@RequestParam(name = "page", required = false, defaultValue = "1") int page,
                            @RequestParam(name = "size", required = false, defaultValue = "10") int size) {
        System.out.println(page + " " + size);
        return "OK";
    }

    /**
     * 保存用户的方法
     *
     * @param user
     * @return
     */
    @PostMapping
    public Object saveUser(@RequestBody User user) {
        System.out.println(user);
        return "ok";
    }

    /**
     * 查询用户详情的方法
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public Object detailUser(@PathVariable Integer id) {
        System.out.println(id);
        return "ok";
    }

    /**
     * 修改用户信息的方法
     * @param user
     * @return
     */
    @PutMapping
    public Object updateUser(@RequestBody User user){
        System.out.println(user);
        return "ok";
    }

    /**
     * 删除用户的方法
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    public Object deleteUser(@PathVariable Integer id){
        System.out.println(id);
        return "ok";
    }

    @GetMapping("keyword")
    public Object queryPage(@RequestParam(name = "page", required = false, defaultValue = "1") int page,
                            @RequestParam(name = "size", required = false, defaultValue = "10") int size,
                            @RequestParam(name = "keyword") String keyWord) {
        System.out.println(page + " " + size + " " + keyWord);
        return "OK";
    }
}
